<?php
/**
 * Created by PhpStorm.
 * User: LOPO
 * Date: 2020/4/17
 * Time: 10:30
 */
namespace App\Lib;
/**
 * 做一些反射机制相关的 处理
 * Class ClassArr
 * @package App\Lib
 */
class ClassArr{
    /**
     * @return array
     */
    public function uploadClassStat(){
        return  [
            "image"=>"\App\Lib\Upload\Image",
            "video"=>"\App\Lib\Upload\Video"
        ];
    }

    /**
     * @param $type
     * @param $supportedClass
     * @param array $params
     * @param bool $needInstance
     * @return bool|object
     * @throws \ReflectionException
     */
    public function initClass($type,$supportedClass,$params=[],$needInstance=true){
        if (!array_key_exists($type,$supportedClass)){
            return false;
        }
        $className = $supportedClass[$type];
        return $needInstance ? (new \ReflectionClass($className))->newInstanceArgs($params):$className;
    }
}